package com.torry.workflow.service.wo.service.impl;

import com.alibaba.fastjson.JSON;
import com.torry.workflow.api.wo.entity.ProcessNode;
import com.torry.workflow.api.wo.entity.WoDetail;
import com.torry.workflow.api.wo.entity.WoInfo;
import com.torry.workflow.service.wo.service.IWorkOrderService;
import com.torry.workflow.service.wo.service.IProcessService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service
public class WorkOrderServiceImpl implements IWorkOrderService {

    @Resource
    private IProcessService iProcessService;

    @Override
    public void convertToWo(List<String> contractServiceList, Integer processId, List<ProcessNode> nodes) {
        // 1. 判断是否可转工单
        // 2. 生成工单数据
        WoInfo wo = new WoInfo();
        wo.setId(1);
        // ...

        WoDetail detail = new WoDetail();
        detail.setWoId(wo.getId());
        detail.setProcess(JSON.toJSONString(iProcessService.getWoRealProcess(wo, nodes)));
        // ...
        // 生成计费

        // 记录日志
        // 下一步
    }

    @Override
    public void next(WoInfo wo) {

    }

    @Override
    public void cancelWo(WoInfo wo) {
        WoDetail detail = new WoDetail();
        iProcessService.revertProcess(detail);

        next(wo);
    }

    @Override
    public void createTerminateWo(List<String> serviceList) {

    }

    @Override
    public void createInternalWo(List<String> serviceList) {

    }

    @Override
    public void rollbackWo(List<String> serviceList) {

    }
}
